package mt.demo.service.user;

import mt.demo.dao.UserDao;
import mt.demo.domain.user.UserDomain;
import mt.demo.service.comm.YomsException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by watson on 2015/11/12.
 */
@Service
public class UserService {
    @Autowired
    private UserDao userDao;

    //寻找所有用户
    public List<UserDomain> getAllUser(UserDomain userDomain) throws YomsException {
        List<UserDomain> domains = userDao.getDomainByCondition(userDomain);
        if (domains.size() == 0) {
            throw new YomsException("用户为空");
        } else {
            return domains;
        }
    }

    public UserDomain getUserDomainByUserName(String userLoginName) throws YomsException {
        UserDomain condition = new UserDomain();
        condition.setUserLoginName(userLoginName);
        List<UserDomain> userDomains = userDao.getDomainByCondition(condition);
        if (userDomains.size() == 1) {
            return userDomains.get(0);
        } else {
            throw new YomsException("未找到该用户");
        }
    }
}
